/*
 * @Author: liuYang codkly@gmail.com
 * @Date: 2022-10-26 22:46:47
 * @LastEditors: thirty lycodk@gmail.com
 * @LastEditTime: 2023-02-12 20:33:39
 * @FilePath: \coding\blog\blog_web\server\api\[...].ts
 * @Description: 
 * 暂无备注
 */
// 当做代理 请求接口
import { getQuery, readBody } from 'h3'

const BASE_URL = 'http://127.0.0.1:3003'

export default async (event: any) => {
    // console.log('======1===', event.node)
    console.log('======1===', event.req.url, 'date=>', new Date())
    let options = {
        // method: event.method
    }
    console.log('======2===', options)
    // switch (event.method) {
    //     case 'post':
    //     case 'POST':
    //         options['body'] = await readBody(event)
    //         break;
    //     case 'get':
    //     case 'GET':
    //         options['params'] = getQuery(event)
    //         break;
    //     default:
    //         break;
    // }
    console.log('33==', BASE_URL + event.req.url, options)
    let res = { data: null, msg: '服务器链接失败' }
    try {
        res = await $fetch(BASE_URL + event.req.url, options)
    } catch (e) {
       res.data = null
    }
    console.log('44==', res)
    return res
}
